<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link
	href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css"
	rel="stylesheet">
<link href="${pageContext.request.contextPath}/themes/icon.css"
	rel="stylesheet">
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-1.9.1.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
</head>
<script type="text/javascript">
	$(function() {
	//数据表格加载
	$('#emsg').datagrid({    
		    url:"${pageContext.request.contextPath}/findEmployee", 
		    toolbar:"#toolbar",
		    pagination:true,
		    rownumbers:false,
		    fitColumns:true,
		    singleSelect:true,
		    pagination:true,
		    columns:[[    
		        {field:'e_number',title:'员工编号',width:20},    
		        {field:'e_name',title:'员工名',width:20},    
		        {field:'dept_name',title:'所属部门',width:20},
		        {field:'role_id',title:'角色id',width:20} ,
		        {field:'role_name',title:'职位',width:20},
		        {field:'_operate',title:'修改权限',formatter:formatOper,align:'center',width:20}
		    ]]    
		});  
		//默认对话框是关闭的   
		$('#updataFunc').dialog('close');
		$("#emsg").datagrid('hideColumn', 'role_id');
		$("#sureSearch").click(function(){
			var e_name=$("#searchename").val();
			$('#emsg').datagrid('reload', {
				e_name : e_name,
			});
		})
		//配置修改权限表单的提交
		$("#updateRole").click(function(){
			$('#upFunc').form('submit', {    
			    url:'${pageContext.request.contextPath}/updateRole',       
			    success:function(data){     
			    	$.messager.confirm('确认',data,function(r){    
			    	    if (r){   
			    	    	$('#emsg').datagrid('reload');
			    	    	$('#updataFunc').dialog('close'); 
			    	    	
			    	    }    
			    	}); 
			    }    
			});  
		}) 
	
	})
	function formatOper(val, row, index) {
		return '<a href="#" onclick="editUser(' + index + ')">权限修改</a>';
	}
	function editUser(index) {
		$('#emsg').datagrid('selectRow', index);// 关键在这里  
		var row = $('#emsg').datagrid('getSelected');
		if (row) {
			$('#updataFunc').dialog('open').dialog('setTitle', '分配权限');
			$('#upFunc').form('load', row);
		}
		
		
		if(row.role_id==2){
			
			document.getElementById("employee").checked = true;
		}else{
			document.getElementById("manger").checked = true;
		} 
		$('#cc').combotree({    
		    url: '${pageContext.request.contextPath}/currentfunc?e_number='+row.e_number+'&&role_name=', 
		    width:200,
		    required: true   
		});
		$("#employee").click(function(){
			 $('#cc').combotree({    
				    url: '${pageContext.request.contextPath}/currentfunc?e_number='+row.e_number+'&&role_id=1', 
				    width:200,
				    required: true   
				});
			  });
		 $("#manger").click(function(){
			 $('#cc').combotree({    
				    url: '${pageContext.request.contextPath}/currentfunc?e_number='+row.e_number+'&&role_id=2', 
				    width:200,
				    required: true   
				});
			  });
		
	}
</script>
<body>
	<input id="searchename" class="easyui-textbox"  style="width:300px"><a id="sureSearch" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok',height:20">确定</a>
	<table id="emsg"></table>  	
	<!-- 修改的对话框 -->
	<div id="updataFunc" class="easyui-dialog" title="更新学生信息"
		style="width: 400px; height: 450px;" data-options="modal:true">
		<form id="upFunc" method="post">
			<div style="margin-bottom: 20px">
				<center><span>员工编号</span> <input class="easyui-textbox" name="e_number"
					style="width: 50;" readonly="readonly"></center>
			</div>
			<div style="margin-bottom: 20px">
				<center><span>员工姓名</span> <input class="easyui-textbox" name="e_name"
					style="width: 50 " data-options="" readonly="readonly"></center>
			</div>
			<div style="margin-bottom: 20px " >
				<center><span>所属部门</span> <input  class="easyui-textbox" name="dept_name"
					style="width: 50" data-options="" readonly="readonly"></center>
			</div>
			<div style="margin-bottom: 20px ; display: none">
				<center><span>权限编号</span> <input class="easyui-textbox" name="role_id"
					style="width: 50" data-options=""></center>
			</div>
			<center><span>请重新选择权限：</span><input type="radio" id="employee" name="role" value=2 />员工 <input type="radio" id="manger" name="role" value=1>经理 </center> 
			<center><span>拥有功能预览：</span><input id="cc" value="01" ></center> 
		</form>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<br>
		<div style="text-align: center; padding: 5px 0">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				id="updateRole" style="width: 80px">提交</a>
		</div>
</body>
</html>